package com.david.service;

import com.david.dao.CategoryDao;
import com.david.entity.Category;
import com.david.utils.DateTimeUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CategoryService {

    @Resource
    CategoryDao categoryDao;

    public List<Category> findAll() {
        return categoryDao.findAll();
    }

    public List<Category> findCategoryByParentId(int parentId) {
        return categoryDao.findCategoryByParentId(parentId);
    }


    public Category findById(Integer id) {
        return categoryDao.findById(id);
    }

    public int delete(Integer id) {
        return categoryDao.delete(id);
    }

    public int update(Category category) {
        return categoryDao.update(category);
    }

    public int insert(Category category) {
        category.createTime = DateTimeUtils.GetPSTDateTime();
        category.isDelete = false;
        category.isEnable = true;
        return categoryDao.insert(category);
    }

    public int updateRoute(String route, int id) {
        return categoryDao.updateRoute(route, id);
    }
}
